﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using DevComponents.AdvTree;

namespace project_assess.prj_view
{
    public partial class manager_change : Office2007Form
    {
        Mfrm mfrm;
        DataBase m_db;
        public bool yesno = false;
        public string oldname;
        public string newname;
        public manager_change(Mfrm frm,string newn,string old )
        {
            InitializeComponent();
            mfrm = frm;
            m_db = frm.m_db;
            newname = newn;
            oldname = old;
            load_data();
        }
        private void slider2_ValueChanged(object sender, EventArgs e)
        {
            l2.Text = slider2.Value.ToString() + "%";
        }
        DateTime lastassessTime;
        int lastratio;
        void load_data()
        {
            string sql = "select [终止比例],[终止时间] from [assess_work] where [项目编号]='"
                + mfrm.curprjid + "' order by [终止时间] desc";
            DataTable dt = m_db.GetDataSet(sql).Tables[0];
            if (dt == null || dt.Rows.Count == 0)
            {
                slider2.Value = 0;
                lbtime.Text = "未进行工作量考核";
            }
            else
            {
                slider2.Value = Convert.ToInt32(dt.Rows[0]["终止比例"]);
                lastratio = slider2.Value;
                lastassessTime  = Convert.ToDateTime(dt.Rows[0]["终止时间"]);
                dateTimePicker1.MinDate = lastassessTime;
                slider2.Minimum = lastratio;
                lbtime.Text = lastassessTime.ToShortDateString();
            }
            label.Text = "项目经理由\"" + oldname + "\"更换为\"" + newname + "\"";
        }

        private void btnok_Click(object sender, EventArgs e)
        {
            assess_work();
            yesno = true;
            this.Hide();
            mfrm.msg("已完成项目经理的更改");
        }
        private void assess_work()
        {
            if (slider2.Value == lastratio)
            {
                return;
            }
            double ratio = ((double)(slider2.Value - lastratio)) / 100;
            string sql = "select [工作量] from [projects] where [项目编号]='"
              + mfrm.curprjid + "'";
            DataTable dt = m_db.GetDataSet(sql).Tables[0];
            double max = Convert.ToDouble(dt.Rows[0][0]);
            double prjfee = ratio * max * mfrm.get_para("工作量项目额度") * mfrm.get_para("工作量提取额度");
            double teamfee = ratio * max * mfrm.get_para("工作量班组额度") * mfrm.get_para("工作量提取额度");
            prjfee = Math.Round(prjfee, 2);
            teamfee = Math.Round(teamfee, 2);
            double no = 1;
            sql = "Insert into [assess_work] values('" + mfrm.curprjid + "'," + no
                + ",'" + lastassessTime.ToShortDateString() + "'," + lastratio + ",'" + dateTimePicker1.Value.ToShortDateString()
            + "'," + slider2.Value + "," + prjfee + "," + teamfee + ",'" + newname + "','','','')";//记录项目经理的更改
            m_db.ExecuteSQL(sql);
        }
        private void btnno_Click(object sender, EventArgs e)
        {
            yesno = false ;
            this.Hide();
            mfrm.msg("已取消项目经理的更改");
        }


    }
}
